<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div>

  <card-layout header-css="filter-header" class="centered">

    <header-section>
      <div layout="row" layout-align="center start">
        <div class="card-title">{{"views.import_feed.Import_a_feed" | translate}}</div>
        <span flex></span>
        <ng-md-icon icon="file_upload" style="fill:#F08C38;padding-right:36px;" size="30"></ng-md-icon>
      </div>
    </header-section>


    <body-section>


      <div layout="column" class="md-padding">
        <div>
          <div class="card-sub-header">{{"views.import_feed.Import_a_Feed_Archive" | translate}}</div>
        </div>
        <div class="layout-padding-indent">
          <md-list layout-fill class="list-item-table list-condensed">

            <md-list-item>
              <div layout="row" layout-fill>
                <div flex="20" class="md-list-item-text hint">
                  {{"views.import_feed.Type" | translate}}
                </div>
                <div flex="10" class="md-list-item-text hint">
                  {{"views.import_feed.File_type" | translate}}
                </div>
                <div flex="60" class="md-list-item-text hint">
                  {{"views.import_feed.Description" | translate}}
                </div>

              </div>
            </md-list-item>

            <md-list-item>
              <div layout="row" layout-fill>
                <div flex="20" class="md-list-item-text ">
                  {{"views.import_feed.Archive" | translate}}
                </div>
                <div flex="10" class="md-list-item-text ">
                  {{"views.import_feed.ZIP" | translate}}
                </div>
                <div flex="60" class="md-list-item-text ">
                  {{"views.import_feed.NifiKylo" | translate}}
                  <Br/>
                  {{"views.import_feed.NifiKylo2" | translate}}
                </div>
              </div>
            </md-list-item>
          </md-list>
        </div>

        <div layout="column" layout-align="start" style="padding-top:15px;"
             class="layout-padding-indent">
          <upload-file upload-file-model="vm.feedFile"></upload-file>
          <ng-form name="vm.importFeedForm">
            <div layout="row">
              <div layout="column" flex>
                <div layout="row" class="feed import category">
                  <md-autocomplete flex ng-disabled="vm.categoryModel.id != null"
                                   md-input-name="category"
                                   md-selected-item="vm.category"
                                   md-search-text-change="vm.categorySearchTextChanged(vm.categorySearchText)"
                                   md-search-text="vm.categorySearchText"
                                   md-selected-item-change="vm.categorySelectedItemChange(item)"
                                   md-items="item in vm.categoriesService.querySearch(vm.categorySearchText)"
                                   md-item-text="item.name"
                                   md-min-length="0"
                                   md-floating-label = "{{'views.import_feed.Change_the_Category' | translate}}"
                                   md-require-match="true"
                                   md-select-on-match="true"
                                   md-menu-class="autocomplete-categories-template">
                    <md-item-template>
                        <span class="item-title">
                             <ng-md-icon icon="{{item.icon}}" ng-style="{'fill':item.iconColor}"></ng-md-icon>
                          <span> {{item.name}} </span>
                        </span>
                      <span class="item-metadata">
                    <span class="item-metastat hint"  ng-if="item.createFeed">
                     {{item.description | characters:50}}
                    </span>
                  </span>
                    </md-item-template>
                    <md-not-found>
                      {{"views.import_feed.no-catigories "{{vm.categorySearchText}}" {{"views.import_feed.were-found" | translate}}
                    </md-not-found>
                  </md-autocomplete>
                </div>
                <!-- Feed Data container -->
                <!-- validation messages -->
                <div ng-if="vm.feedDataImportOption.errorMessages != null && vm.feedDataImportOption.errorMessages.length >0">
                  <div ng-repeat="message in vm.feedDataImportOption.errorMessages" layout="column">
                    <div>
                      <ng-md-icon icon="warning" size="20" class="warn"></ng-md-icon>
                      <span>{{message}}</span></div>
                  </div>
                </div>

                <div layout="row">
                  <md-input-container class="condensed-no-float md-block layout-padding-bottom" flex="50">
                    <md-checkbox ng-model="vm.feedDataImportOption.overwrite" aria-label="Overwrite if exists">
                      {{"views.import_feed.Overwrite_Feed" | translate}}
                    </md-checkbox>
                    <div class="hint" style="margin-top:-10px">
                      {{"views.import_feed.Overwrite_Feed2" | translate}}
                    </div>
                  </md-input-container>

                  <md-input-container class="condensed-no-float md-block layout-padding-bottom" flex="50">
                    <md-checkbox ng-model="vm.disableFeedUponImport" aria-label="Disable upon import">
                      {{"views.import_feed.Disable_Feed" | translate}}
                    </md-checkbox>
                    <div class="hint" style="margin-top:-10px">
                      {{"views.import_feed.Disable_Feed2" | translate}}
                    </div>
                  </md-input-container>

                </div>

                <!-- Template Data Container -->
                <!-- validation messages -->
                <div  ng-if="vm.templateDataImportOption.errorMessages != null && vm.templateDataImportOption.errorMessages.length >0">
                  <div ng-repeat="message in vm.templateDataImportOption.errorMessages" layout="column">
                    <div>
                      <ng-md-icon icon="warning" size="20" class="warn"></ng-md-icon>
                      <span>{{message}}</span></div>
                  </div>
                </div>

                <div ng-if="vm.nifiTemplateImportOption.errorMessages != null && vm.nifiTemplateImportOption.errorMessages.length >0">
                  <div ng-repeat="message in vm.nifiTemplateImportOption.errorMessages" layout="column">
                    <div>
                      <ng-md-icon icon="warning" size="20" class="warn"></ng-md-icon>
                      <span>{{message}}</span></div>
                  </div>
                </div>



                <div layout="row">
                  <md-input-container class="condensed-no-float md-block layout-padding-bottom" flex="50">
                    <md-checkbox ng-model="vm.templateDataImportOption.overwrite" aria-label="Overwrite if exists">
                      {{"views.ipmort_feed.Replace_Feed" | translate}}
                    </md-checkbox>
                    <div class="hint" style="margin-top:-10px">
                      {{"views.ipmort_feed.Replace_Feed2" | translate}}
                    </div>
                  </md-input-container>

                  <md-input-container class="condensed-no-float md-block layout-padding-bottom" flex="50">
                    <md-checkbox ng-model="vm.reusableTemplateImportOption.overwrite" aria-label="Replace Reusable Template">
                      {{"views.ipmort_feed.Replace_Reusable" | translate}}
                    </md-checkbox>
                    <div class="hint" style="margin-top:-10px">
                      {{"views.ipmort_feed.Replace_Reusable2" | translate}}
                    </div>
                  </md-input-container>

                </div>


                <!-- Feed properties required -->

                <div ng-if="vm.feedDataImportOption.properties && vm.feedDataImportOption.properties.length >0" flex layout="column">
                  <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                  <div ng-repeat="prop in vm.feedDataImportOption.properties" layout="column" layout-align="start start">
                    <span>Processor: {{prop.processorName}}</span>
                    <div layout="row" flex layout-fill>
                      <md-input-container>
                        <label>{{prop.propertyKey}}</label>
                        <input type="text" ng-model="prop.propertyValue" autocomplete="new-password" name="{{prop.inputName}}">
                      </md-input-container>
                    </div>
                  </div>
                </div>

                <!-- Data source properties required -->
                <div ng-if="vm.userDatasourcesOption.properties && vm.userDatasourcesOption.properties.length > 0" flex layout="column">
                  <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                  <div ng-repeat="prop in vm.userDatasourcesOption.properties" layout="column" layout-align="start start">
                    <span>Data Source: {{prop.processorName}}</span>
                    <div layout="row" flex layout-fill>
                      <md-input-container>
                        <md-select ng-model="prop.propertyValue" placeholder="Select new data source">
                          <md-option ng-value="datasource.id" ng-repeat="datasource in vm.availableDatasources">{{datasource.name}}</md-option>
                        </md-select>
                      </md-input-container>
                    </div>
                  </div>
                </div>




                  <div ng-if="vm.templateDataImportOption.properties && vm.templateDataImportOption.properties.length >0 " flex layout="column">
                    <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                    <div ng-repeat="prop in vm.templateDataImportOption.properties" layout="column" layout-align="start start">
                      <span>{{prop.processorName}}</span>
                      <div layout="row" flex layout-fill>
                        <md-input-container>
                          <label>{{prop.propertyKey}}</label>
                          <input type="text" ng-model="prop.propertyValue" autocomplete="new-password" name="{{prop.inputName}}">
                        </md-input-container>
                      </div>
                    </div>
                  </div>



                  <div ng-if="vm.reusableTemplateImportOption.properties && vm.reusableTemplateImportOption.properties.length >0" flex layout="column">
                    <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                    <div ng-repeat="prop in vm.reusableTemplateImportOption.properties" layout="column" layout-align="start start">
                      <span>{{prop.processorName}}</span>
                      <div layout="row" flex layout-fill>
                        <md-input-container>
                          <label>{{prop.propertyKey}}</label>
                          <input type="text" ng-model="prop.propertyValue" autocomplete="new-password" name="{{prop.inputName}}">
                        </md-input-container>
                      </div>
                    </div>
                  </div>

                <div ng-if="vm.feedUserFieldsImportOption.properties && vm.feedUserFieldsImportOption.properties.length >0 " flex layout="column">
                  <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                  <div ng-repeat="prop in vm.feedUserFieldsImportOption.properties" layout="column" layout-align="start start">
                    <div layout="row" flex layout-fill>
                      <md-input-container>
                        <label>{{prop.displayName}}</label>
                        <input type="text" ng-model="prop.propertyValue" autocomplete="new-password" name="{{prop.inputName}}">
                        <span class="hint">{{prop.description}}</span>
                      </md-input-container>
                    </div>
                  </div>
                </div>

                <div ng-if="vm.categoryUserFieldsImportOption.properties && vm.categoryUserFieldsImportOption.properties.length >0 " flex layout="column">
                  <div class="layout-padding-bottom">{{"views.ipmort_feed.padding_bottom" | translate}}</div>

                  <div ng-repeat="prop in vm.categoryUserFieldsImportOption.properties" layout="column" layout-align="start start">
                    <div layout="row" flex layout-fill>
                      <md-input-container>
                        <label>{{prop.displayName}}</label>
                        <input type="text" ng-model="prop.propertyValue" autocomplete="new-password" name="{{prop.inputName}}">
                        <span class="hint">{{prop.description}}</span>
                      </md-input-container>
                    </div>
                  </div>
                </div>


              </div>

            </div>

            <span style="padding-top:10px"></span>
            <div layout="row" class="layout-padding-top">
              <md-button class="md-raised md-primary" ng-click="vm.importFeed()" ng-if="vm.feedFile != null"
                         ng-disabled="(vm.uploadInProgress || vm.importFeedForm.$invalid)">
                {{"views.import_feed.Import_Feed_btn" | translate}}
              </md-button>
              <md-progress-linear flex md-mode="determinate" value="{{vm.uploadProgress}}" ng-if="vm.uploadInProgress"></md-progress-linear>
            </div>
          </ng-form>
          <div layout="column">
            <div ng-repeat="msg in vm.uploadStatusMessages" layout="row">
              <div flex>
                <span ng-if="msg.complete && msg.success">
                   <ng-md-icon icon="check" size="20" style="fill:green"></ng-md-icon>
                </span>
                <span ng-if="msg.complete && !msg.success">
                  <ng-md-icon icon="error" size="20" style="fill:red"></ng-md-icon>
                </span>
                <span>{{msg.message}}</span>
              </div>
            </div>
          </div>


          <div ng-if="vm.importResult != null" class="layout-padding-top">
            <div layout="row">
              <ng-md-icon icon="{{vm.importResultIcon}}"
                          ng-style="{'fill':vm.importResultIconColor}"></ng-md-icon>
              <span style="padding-left:15px;">{{vm.message}}</span>
              <span flex></span>
            </div>
            <md-list class="padding-left" ng-repeat="(severity,errors)  in vm.errorMap">
              <md-list-item class="md-2-line" ng-repeat="error in errors track by $index">
                <div class="md-list-item-text">
                  <div ng-if="error.processorName != null && error.processorName != '' "
                       style="color:grey">Processor: {{::error.processorName}}
                  </div>
                  <div class="md-warn-text">{{::error.message}}</div>
                </div>
                <md-divider ng-if="!$last"></md-divider>
              </md-list-item>
            </md-list>
          </div>
        </div>
      </div>
    </body-section>
  </card-layout>
</div>
